﻿Imports System
Imports System.Globalization
Imports System.Reflection

Namespace System.Workflow.Activities.Rules
    Friend Class RulePropertyResult
        Inherits RuleExpressionResult
        ' Methods
        Public Sub New(ByVal propertyInfo As PropertyInfo, ByVal targetObject As Object, ByVal indexerArguments As Object())
            If (propertyInfo Is Nothing) Then
                Throw New ArgumentNullException("propertyInfo")
            End If
            Me.targetObject = targetObject
            Me.propertyInfo = propertyInfo
            Me.indexerArguments = indexerArguments
        End Sub


        ' Properties
        Public Overrides Property Value As Object
            Get
                Dim obj2 As Object
                If (Not Me.propertyInfo.GetGetMethod(True).IsStatic AndAlso (Me.targetObject Is Nothing)) Then
                    Dim exception As New RuleEvaluationException(String.Format(CultureInfo.CurrentCulture, Messages.TargetEvaluatedNullProperty, New Object() { Me.propertyInfo.Name }))
                    exception.Data.Item("ErrorObject") = Me.propertyInfo
                    Throw exception
                End If
                Try 
                    obj2 = Me.propertyInfo.GetValue(Me.targetObject, Me.indexerArguments)
                Catch exception2 As TargetInvocationException
                    If (exception2.InnerException Is Nothing) Then
                        Throw
                    End If
                    Throw New TargetInvocationException(String.Format(CultureInfo.CurrentCulture, Messages.Error_PropertyGet, New Object() { RuleDecompiler.DecompileType(Me.propertyInfo.ReflectedType), Me.propertyInfo.Name, exception2.InnerException.Message }), exception2.InnerException)
                End Try
                Return obj2
            End Get
            Set(ByVal value As Object)
                If (Not Me.propertyInfo.GetSetMethod(True).IsStatic AndAlso (Me.targetObject Is Nothing)) Then
                    Dim exception As New RuleEvaluationException(String.Format(CultureInfo.CurrentCulture, Messages.TargetEvaluatedNullProperty, New Object() { Me.propertyInfo.Name }))
                    exception.Data.Item("ErrorObject") = Me.propertyInfo
                    Throw exception
                End If
                Try 
                    Me.propertyInfo.SetValue(Me.targetObject, value, Me.indexerArguments)
                Catch exception2 As TargetInvocationException
                    If (exception2.InnerException Is Nothing) Then
                        Throw
                    End If
                    Throw New TargetInvocationException(String.Format(CultureInfo.CurrentCulture, Messages.Error_PropertySet, New Object() { RuleDecompiler.DecompileType(Me.propertyInfo.ReflectedType), Me.propertyInfo.Name, exception2.InnerException.Message }), exception2.InnerException)
                End Try
            End Set
        End Property


        ' Fields
        Private indexerArguments As Object()
        Private propertyInfo As PropertyInfo
        Private targetObject As Object
    End Class
End Namespace

